<template>
  <div class="register">
    <el-form ref="registerForm" :model="registerForm" :rules="registerRules" class="register-form">
      <h3 class="title">帮扶预约</h3>

      <el-form-item prop="studentName">
        <el-input v-model="registerForm.studentName" type="text" auto-complete="off" placeholder="请输入你的真实姓名">
          <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
        </el-input>
      </el-form-item>

      <el-form-item prop="wecat">
        <el-input v-model="registerForm.wecat" type="text" auto-complete="off" placeholder="请填写正确的微信">
          <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
        </el-input>
      </el-form-item>

      <el-form-item prop="stuPhone">
        <el-input v-model="registerForm.stuPhone" type="text" auto-complete="off" placeholder="请填写正确的电话">
          <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
        </el-input>
      </el-form-item>

      <el-form-item prop="className">
        <el-select v-model="registerForm.className" placeholder="所在班级">
          <el-option
            v-for="item in classess"
            :label="item.className"
            :value="item.className">
            <span style="float: left">{{ item.className }}</span>
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item  prop="appointmentTime">
        <el-date-picker clearable
                        v-model="registerForm.appointmentTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="请选择预约时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item  prop="problemType">
        <el-select v-model="registerForm.problemType" placeholder="请选择问题类型">
          <el-option
            v-for="dict in dict.type.problem_type"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item  prop="teacherName">
        <el-select v-model="registerForm.teacherName" placeholder="意向老师">
          <el-option
            v-for="item in teachers"
            :label="item.teacherName"
            :value="item.teacherName">
            <span style="float: left">{{ item.teacherName }}</span>
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item prop="intro">
        <el-input v-model="registerForm.intro" type="textarea" placeholder="问题描述" />
      </el-form-item>


      <el-form-item style="width:100%;">
        <el-button
          :loading="loading"
          size="medium"
          type="primary"
          style="width:100%;"
          @click.native.prevent="handleRegister"
        >
          <span v-if="!loading">提交预约</span>
          <span v-else>预 约 中...</span>
        </el-button>
      </el-form-item>
    </el-form>
    <!--  底部  -->
    <div class="el-register-footer">
      <span>Copyright © 2018-2022 ruoyi.vip All Rights Reserved.</span>
    </div>
  </div>
</template>

<script>
import {addAssist} from "@/api/education/assist";
import {listTeacher} from "@/api/education/teacher";
import {listClasses} from "@/api/education/classes";

export default {
  name: "Help",
  dicts: ['problem_type'],
  data() {
    return {
      codeUrl: "",
      registerForm: {
        studentName: "",
        className:"",
        wecat: "",
        appointmentTime: "",
        stuPhone: "",
        problemType: "",
        teacherName: "",
        intro: ""
      },
      teachers:[],
      classess:[],
      registerRules: {
        studentName: [
          { required: true, trigger: "blur", message: "请输入你的姓名" },
        ],
        wecat: [
          { required: true, trigger: "blur", message: "不能为空" },
        ],
        stuPhone: [
          { required: true, trigger: "blur", message: "不能为空" },
        ],
        intro: [
          { required: true, trigger: "blur", message: "不能为空" }]
      },
      loading: false,
      captchaEnabled: true
    };
  },
  created() {
    this.getTeachers();
    this.getClassess();
  },
  methods: {
    handleRegister() {
      this.$refs.registerForm.validate(valid => {
        if (valid) {
          this.loading = true;
          addAssist(this.registerForm).then(res => {
            const teacherName = this.registerForm.teacherName;
            this.$alert("<font color='red'>帮扶预约成功，请等待 " + teacherName + " 老师联系你！</font>", '系统提示', {
              dangerouslyUseHTMLString: true,
              type: 'success'
            }).then(() => {
              this.$router.push("/help");
            }).catch(() => {});
          })
        }
      });
    },
    getTeachers(){
      listTeacher().then(res =>{
        this.teachers = res.rows;
      })
    },
    getClassess(){
      listClasses().then(res =>{
        this.classess = res.rows;
      })
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.register {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/images/login-background.jpg");
  background-size: cover;
}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.register-form {
  border-radius: 6px;
  background: #ffffff;
  width: 400px;
  padding: 25px 25px 5px 25px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.register-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.register-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-register-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.register-code-img {
  height: 38px;
}
</style>
